<?php

namespace StudyBuddy\Forms;

/**
 * Class responsible
 * for processing the "Ask" form
 *
 */
class Edit extends Form {

    /**
     * Name of form template file
     * The name of actual template should be
     * set in sub-class
     *
     * @var string
     */
    protected $template = 'tplFormedit';

    /**
     * Concrete form validator for this form
     * (non-PHPdoc)
     * @see Form::doValidate()
     */
    protected function doValidate() {

        $this->validateBody()->validateReason();
    }

    protected function validateBody() {
        $body = $this->oRegistry->Request['qbody'];
        if (strlen($body) < 10) {
            $this->setError('qbody', 'Question must contain at least 10 letters');
        }

        $aWords = explode(' ', $body);
        if (count($aWords) < 3) {
            $this->setError('qbody', 'Question must contain at least 3 words');
        }

        return $this;
    }

    protected function validateReason() {
        $s = $this->oRegistry->Request->get('reason', 's', '');
        $s = trim($s);
        if (empty($s)) {
            $this->setError('reason', 'You must include reason for editing');
        }



        return $this;
    }

}
